---
title: "Adult Census"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
social: menu
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(plotly)
library(knitr)
library(DT)
df <- read_csv('adult_census.csv')
# Create a ggplot object
p <- df %>%
mutate(sex = factor(sex)) %>%
ggplot()+
geom_bar(mapping=aes(x=income, fill=sex),
position = 'fill')+
labs(y='Proportion', fill='Sex')
p1 <- df %>%
mutate(sex = factor(sex)) %>%
ggplot()+
geom_density(mapping=aes(x=age, color=sex))+
facet_wrap(~education)
```
# {.sidebar}
### 1. Adult Census
The adult census dataset includes demographic information from 1000s of individuals.It is typically used to predict income earning level based on provided demographic information.
### 2. Flexdashboard and Plotly
This interactive uses `flexdashboard` and `plotly` to visualize the data.
# Main Tab 1
## Column {.tabset data-width="500,"}
### Column Tab 1
```{r}
head(df)
```
### Column Tab 2
```{r, eval=FALSE}
kable(df)
```
### Column Tab 3
```{r, eval=FALSE}
datatable(df, options = list(
pageLength = 25
))
```
## Column {data-width="500"}
### Row 1
```{r, eval=FALSE}
p
```
### Row 2
```{r, eval=FALSE}
ggplotly(p)
```
# Main Tab 2
## Column {data-width="500"}
#### 1. Plotly for R
Plotly is an R package for creating interactive web-based graphs via plotly's JavaScript graphing library, plotly.js.
The plotly R package serializes ggplot2 figures into Plotly's universal graph JSON. plotly::ggplotly will crawl the ggplot2 figure, extract and translate all of the attributes of the ggplot2 figure into JSON (the colors, the axes, the chart type, etc), and draw the graph with plotly.js. Furthermore, you have the option of manipulating the Plotly object with the style function.
#### 2. Cutomizing the Layout
Since the ggplotly() function returns a plotly object, we can manipulate that object in the same way that we would manipulate any other plotly object. A simple and useful application of this is to specify interaction modes, like plotly.js' layout.dragmode for specifying the mode of click+drag events.
#### 3. Example
```{r, echo=TRUE, eval=FALSE}
library(plotly)
df <- data.frame(x=c(1, 2, 3, 4), y=c(1, 5, 3, 5), group=c('A', 'A', 'B', 'B'))
p <- ggplot(data=df, aes(x=x, y=y, colour=group)) + geom_point()
ggplotly(p)
```
## Column {data-width="500"}
### Row 1
```{r, eval=FALSE}
p1
```
### Row 2
```{r, eval=FALSE}
ggplotly(p1)
```